Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPORT] Intégrer les champs d'import lors de l'installation d'un protocole #398

Draft
wants to merge 36 commits into
base: develop
Choose a base branch
from

Conversation

jules-jean-louis1
Copy link

[IMPORT][MONITORING] IM_IMPORT_01.0 - Intégrer les champs d'import lors de l'installation d'un protocole https://github.com/orgs/PnX-SI/projects/13/views/6?pane=issue&itemId=83656221

Intégration des champs d'import lors de l'installation d'un protocole

Ajout dans la table bib_destinations

  • Intégration du protocole installé dans la table bib_destinations.

Récupération et insertion des entités

  • Lecture des entités définies dans le fichier config.json du module.
  • Ajout des entités récupérées dans la table bib_entities.

Gestion des champs spécifiques et génériques

  • Génération d'un fichier JSON contenant :
    • Les champs génériques (surcouche).
    • Les champs spécifiques au protocole.
  • Insertion de ces champs dans les tables bib_fields et cor_entity_field.

Création de la table d'import

  • Mise en place d’une nouvelle table dédiée : t_import_{protocole}.
  • Cette table contiendra l'ensemble des champs du protocole, et sera ajoutée au schéma gn_imports.

jacquesfize and others added 18 commits December 13, 2024 10:16
* VESION and requirements.in

* Docs

* Changelog 1.0.0 / complément

* Update README.md

* Update docs/changelog.md

* Bump GeoNature

* Add postgis ltree extension

* Suppression données orpheline synthese

* Use geonature 03b_populate_db.sh script

* Changelog

---------

Co-authored-by: Camille Monchicourt <[email protected]>
…tions/gn_module_monitoring into feat/import/install-protocol
@camillemonchicourt
Copy link
Member

Il faudrait rebaser la branche de destination sur DEVELOP, car là la PR semble ajouter des commits qui sont liés à d'autres évolutions récentes de DEVELOP.

@jules-jean-louis1 jules-jean-louis1 marked this pull request as draft December 23, 2024 14:37
@jules-jean-louis1 jules-jean-louis1 changed the base branch from feat/import-monitoring to develop December 23, 2024 15:21
jacquesfize and others added 9 commits December 23, 2024 16:39
* VESION and requirements.in

* Docs

* Changelog 1.0.0 / complément

* Update README.md

* Update docs/changelog.md

* Bump GeoNature

* Add postgis ltree extension

* Suppression données orpheline synthese

* Use geonature 03b_populate_db.sh script

* Changelog

---------

Co-authored-by: Camille Monchicourt <[email protected]>
Comment on lines 21 to 25
from geonature.core.imports.models import BibFields
from geonature.core.imports.models import Destination
from geonature.core.imports.models import Entity
from geonature.core.imports.models import EntityField
from geonature.core.imports.models import BibThemes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from geonature.core.imports.models import BibFields
from geonature.core.imports.models import Destination
from geonature.core.imports.models import Entity
from geonature.core.imports.models import EntityField
from geonature.core.imports.models import BibThemes
from geonature.core.imports.models import BibFields, Destination, Entity, EntityField, BibThemes

Destination: L'objet Destination inséré ou mis à jour.
"""
existing_destination = (
DB.session.query(Destination).filter_by(code=module_data["module_code"]).one_or_none()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DB.session.query(Destination).filter_by(code=module_data["module_code"]).one_or_none()
DB.session.execute(select(Destination).filter_by(code=module_data["module_code"])).scalar_one_or_none()

Comment on lines 532 to 533
destination = Destination()
destination.from_dict(destination_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
destination = Destination()
destination.from_dict(destination_data)
destination = Destination(**destination_data)

DB.session.commit()
return existing_destination

module_monitoring_code = DB.session.query(TModules).filter_by(module_code=module_data["module_code"]).one()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module_monitoring_code = DB.session.query(TModules).filter_by(module_code=module_data["module_code"]).one()
module_monitoring_code = DB.session.execute(select(TModules).filter_by(module_code=module_data["module_code"])).scalar_one()


fields.append(create_bib_field(field_data, entity_code, field_name, id_destination, json.dumps(field_data)))

if field_data.get("required", False):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les champs additionnels peuvent être requis ?

Jules Jean-Louis added 2 commits January 16, 2025 16:37
…refactor function, add distinction between generic and specific field
Args:
module_data (dict): Données de la table gn_commons.t_modules du module à importer.
"""
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ajouter db.session.begin_nested(). Cela permettra d'annuler toutes les transactions effectuées si une des requêtes échoue. https://docs.sqlalchemy.org/en/20/orm/session_transaction.html#using-savepoint

Destination: L'objet Destination inséré ou mis à jour.
"""
existing_destination = (
DB.session.execute(select(Destination).filter_by(code=module_data["module_code"])).scalar_one_or_none()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DB.session.execute(select(Destination).filter_by(code=module_data["module_code"])).scalar_one_or_none()
DB.session.execute(sa.exists(Destination).where(Destination.code ==module_data["module_code"]).select())

Comment on lines +604 to +608
Args:
field_data (dict): Données du champ

Returns:
str: Type de colonne PostgreSQL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +834 to +837
if DB.session.execute(
select(EntityField)
.filter_by(id_entity=entity_id, id_field=id_field)
).one_or_none():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A remplacer par une requête exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants